package ge.telasi.tasks.model.validation;

import ge.telasi.tasks.LocaleManager;
import ge.telasi.tasks.TaskException;
import ge.telasi.tasks.model.Structure;

/**
 * @author dimitri
 */
public class StructureValidator extends Validator {

    public void validateFull(Structure struct) {
        validateName(struct.getName());
        validateName2(struct.getName2());
        validateType(struct.getType());
    }

    public void validateName(String structureName) {
        String name = "Structure.name";
        String value = structureName;
        new EmptyFieldValidator().validate(name, value);
        new TextRangeValidator(-1, 255).validate(name, value);
    }

    public void validateName2(String structureName2) {
        String name = "Structure.name2";
        String value = structureName2;
        new TextRangeValidator(-1, 255).validate(name, value);
    }

    public void validateType(int type) {
        switch (type) {
            case Structure.DEPARTMENT:
            case Structure.DIRECTION:
            case Structure.DIVISION:
            case Structure.GROUP:
            case Structure.JOB:
                break;
            default:
                LocaleManager lm = getLocaleManager();
                String msg = lm.getMessage("StructureValidator.illegalType", type);
                throw new TaskException(msg, "Structure.type");
        }
    }

}
